package com.wushijia.datastructure.tree;

import com.wushijia.datastructure.tree.BinaryNode;
import com.wushijia.datastructure.tree.BinaryTree;

public class ShiYan8 {

  public static BinaryTree<String> create() {
    BinaryNode<String> child_f, child_d, child_b, child_c, child_a;
    child_d = new BinaryNode<String>("D", null, new BinaryNode("G"));
    child_b = new BinaryNode<String>("B", child_d, null);
    child_f = new BinaryNode<String>("F", new BinaryNode("H"), null);
    child_c = new BinaryNode<String>("C", new BinaryNode("E"), child_f);
    child_a = new BinaryNode("A", child_b, child_c);
    return new BinaryTree<String>(child_a);
  }

  public static void main(String args[]) {
    BinaryTree<String> bitree = create();
    bitree.preOrder();
    bitree.inOrder();
    bitree.postOrder();
    System.out.println();

    System.out.println("bitree.countLeaf()=" + bitree.countLeaf());

    BinaryNode<String> find = bitree.search("D");
      if (find == null) {
          System.out.println("D don't find!");
      } else {
          System.out.println("D's level is:" + bitree.level(find));
      }
  }
}